<template>
  <div>
    <MusicSearch @isSuggest="isSuggest" />

    <div v-show="show">
      <van-grid :border="false" :column-num="5">
        <van-grid-item v-for="item in dragon" :key="item.id" :icon="item.iconUrl" :text="item.name" />
      </van-grid>

      <div class="recom">
        <h2>精选歌单</h2>
        <div class="item1">
          <swiper :slides-per-view="3.2">
            <swiper-slide v-for="item in personalized" :key="item.id">
              <img :src="item.picUrl + '?param=200y200'" />
              <div class="title">{{ item.name }}</div>
            </swiper-slide>
          </swiper>
        </div>

        <h2>最新单曲</h2>
        <div class="item2">
          <swiper :slides-per-view="1.07">
            <swiper-slide v-for="(item, index) in newsong" :key="index">
              <item-detail v-for="i in item" :key="i.id" :content="i" />
            </swiper-slide>
          </swiper>
        </div>

        <h2>大家都在看</h2>
        <div class="item3">
          <div v-for="item in mvList" :key="item.id">
            <img :src="item.cover" alt="" />
            <div class="title">{{ item.name }} - {{ item.artistName }}</div>
          </div>
        </div>
      </div>

      <div></div>
    </div>
  </div>
</template>

<script>
import { Swiper, SwiperSlide } from 'swiper/vue'
import 'swiper/css'
import _ from 'lodash'

import ItemDetail from './ItemDetail.vue'
import MusicSearch from './MusicSearch.vue'
import { musicApi } from '../../config'
import { get } from '../../request/index'

export default {
  components: {
    Swiper,
    SwiperSlide,
    ItemDetail,
    MusicSearch,
  },
  data() {
    return {
      dragon: [],
      personalized: [],
      newsong: [],
      mvList: [],

      show: true,
    }
  },
  created() {
    this.init()
  },
  methods: {
    init() {
      get(musicApi + '/homepage/dragon/ball').then(res => (this.dragon = res.data))
      get(musicApi + '/personalized?limit=10').then(res => (this.personalized = res.result))
      get(musicApi + '/personalized/newsong?limit=12').then(res => (this.newsong = _.chunk(res.result, 3)))
      get(musicApi + '/top/mv?limit=3').then(res => (this.mvList = res.data))
    },
    isSuggest(b) {
      this.show = !b
    },
  },
}
</script>

<style lang="less" scoped>
.van-grid-item {
  /deep/ img {
    filter: brightness(0);
  }
}
.recom {
  h2 {
    padding-left: 12px;
    line-height: 1.5;
    font-size: 17px;
    font-weight: 700;
    padding-top: 10px;
  }

  .item1 {
    margin-bottom: 10px;
    .swiper-slide {
      font-size: 0;
      padding-left: 12px;
      padding-top: 6px;

      .title {
        font-size: 14px;
        line-height: 1.3;
        padding-top: 6px;

        text-overflow: -o-ellipsis-lastline;
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        line-clamp: 2;
        -webkit-box-orient: vertical;
      }

      img {
        width: 100%;
        border-radius: 8px;
      }
    }
  }

  .item2 {
    margin-bottom: 10px;

    .swiper-slide {
      padding-left: 12px;
    }
  }

  .item3 {
    padding: 12px;

    & > div {
      margin-bottom: 20px;
    }
    img {
      width: 100%;
    }

    .title {
      font-size: 16px;
    }
  }
}
</style>
